package com.info.game;

import com.badlogic.gdx.math.MathUtils;
import com.badlogic.gdx.physics.box2d.Body;
import com.badlogic.gdx.physics.box2d.BodyDef;
import com.badlogic.gdx.physics.box2d.FixtureDef;
import com.badlogic.gdx.physics.box2d.PolygonShape;
import com.badlogic.gdx.physics.box2d.BodyDef.BodyType;
import com.component.game.Component;
import com.component.game.PhysicsComponent;
import com.engine.game.GameObject;
import com.engine.game.Helper;


public class GravityZonePhysicsComponent implements PhysicsComponent{

	private Body body;
	
	@Override
	public void bodyCreation(GameObject object) {
		
		BodyDef zone = new BodyDef();
		zone.type = BodyType.StaticBody;
		zone.position.set(Helper.getCenterFromLeftLow(object.getStage().getScreenMinInWorld(), object.getStage().getScreenMaxInWorld().x,
				object.getStage().getScreenMaxInWorld().y));
		
		
		this.body = object.getPhysicsWorld().createBody(zone);
		
		PolygonShape zoneShape = new PolygonShape();
		zoneShape.setAsBox((object.getStage().getScreenMaxInWorld().x/2), (object.getStage().getScreenMaxInWorld().y/2));
		
		FixtureDef zoneFix = new FixtureDef();
		zoneFix.shape = zoneShape;
		zoneFix.isSensor = true;
		
		
		
		this.body.createFixture(zoneFix).setUserData(object.name);;
		
		this.body.setUserData(object);
		
	}
	
	@Override
	public void dispose() {
		
		this.body.getWorld().destroyBody(this.body);
	}

	@Override
	public void update(GameObject object) {
		
		
		
	}

	@Override
	public void collisionWith(GameObject me, String enemy) {
		
		
		
		me.generate("set_gravity_scale;-1", enemy, Component.Physics);
		
	}
	

	@Override
	public float getCenterBodyX() {
		
		return this.body.getPosition().x;
	}

	@Override
	public float getCenterBodyY() {
		
		return this.body.getPosition().y;
	}

	@Override
	public float getBodyAngle() {
		
		return this.body.getAngle() * MathUtils.radiansToDegrees;
	}

	@Override
	public void endCollisionWith(GameObject me, String enemy) {
		
		me.generate("set_standard_gravity", enemy, Component.Physics);
		//me.generate("inverse", enemy, Component.Render);
		
	}

	

	

}
